<template>
  <Header :title="title" :is_img="1"></Header>
  <div
    class="fui-page order-create-page fui-page-current"
    style="height: 100%; margin-top: 40px"
  >
    <!-- 商品 -->
    <div
      class="fui-shop"
      @click="go_url(item.id)"
      v-for="item in list"
      :key="item.id"
    >
      <div style="padding: 0.42rem 0.5rem">
        <div class="subtitle">订单号: {{ item.oid }}</div>
      </div>
      <div class="fui-shop-list" v-for="good in item.goods" :key="good.id">
        <div class="fui-shop-list-media">
          <img class="img" :src="good.img.split(';')[0]" />
        </div>
        <div class="shops" style="folat: left">
          <div class="subtitle">
            {{ good.title }}
          </div>
        </div>
        <div class="fui-list-angle">
          <span style="font-size: 0.65rem; color: #000"
            >￥<span class="marketprice">{{ good.price }}</span></span
          >
          <div style="color: #999">x{{ good.orderNum }}</div>
        </div>
      </div>
    </div>
    <!-- 商品end -->
  </div>
</template>
<script>
import { useRouter } from "vue-router";
import Header from "../../components/Header.vue";
import { orderList, GoodsDetails } from "../../network/index.js";
import { inject, reactive, toRefs } from "vue";

export default {
  components: {
    Header,
  },
  setup() {
    const route = inject("route");
    const router = inject("router");

    const data = reactive({
      list: [],
    });

    const go_url = (id) => {
      router.push({
        path: "my_order_details",
        query: { id },
      });
    };

    orderList().then((res) => {
      data.list = res;
      data.list.forEach((item) => {
        var goodIds = item.shop_id.split(";");
        // 单件商品
        if (goodIds.length <= 1) {
          GoodsDetails({ id: item.shop_id }).then((res) => {
            item.goods = [res];
          });
        } else {
          // 多件商品
          GoodsDetails({ id: item.shop_id, type: 2 }).then((res) => {
            item.goods = res;
            const num = item.num.split(";");
            item.goods.forEach((good, index) => {
              good.orderNum = num[index];
            });
          });
        }
      });
      console.log("data.list", data.list);
    });

    return {
      go_url,
      title: "订单列表",
      ...toRefs(data),
    };
  },
};
</script>
<style scoped>
.fui-page {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: #f3f3f3;
  box-sizing: border-box;
  display: none;
}
.order-create-page {
  margin: 0;
  bottom: 2rem;
  padding-bottom: 2rem;
  display: block;
  overflow: hidden;
}
.fui-content {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.fui-content.navbar {
  padding-bottom: 0.5rem;
}
/* 商品 */
.fui-shop {
  background-color: #fff;
  position: relative;
  margin-top: 0.5rem;
}
.fui-shop-list {
  align-items: center;
  overflow: hidden;
  transition-duration: 300ms;
  display: flex;
  padding: 0.4rem 0.6rem;
  position: relative;
  -webkit-box-align: start;
}
.fui-shop-list-media {
  display: flex;
  align-items: center;
  margin-right: 0.6rem;
  color: #aaa;
  position: relative;
  flex-wrap: nowrap;
  box-sizing: border-box;
  -webkit-box-align: center;
  flex-shrink: 0;
  -webkit-box-lines: single;
}
.img {
  width: 4rem;
  height: 4rem;
}
.shops {
  height: 3.5rem;
  align-self: center;
  justify-content: space-between;
  flex-direction: column;
  -webkit-box-pack: justify;
  display: flex;
  width: 245px;
}
.subtitle {
  color: #000;
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}
.fui-list-angle {
  text-align: right;
  font-size: 0.7rem;
  color: #666;
  margin-right: 0.1rem;
  right: 5px;
  position: absolute;
  vertical-align: middle;
  height: 3.5rem;
  align-self: center;
  width: 3.5rem;
}
.btn {
  overflow: hidden;
  height: auto !important;
  line-height: 2.4rem;
  padding: 0 0.5rem;
  position: relative;
  color: #000;
  font-size: 0.7rem;
}
.status {
  float: right;
}
</style>